package com.yao.utils;

import com.yao.enums.CodeEnum;

/**
 * User: 姚宏武
 * Date: 2017/11/28
 * Time: 14:36
 * Email：401369870@qq.com
 * Description: 枚举工具类
 */
public class EnumUtil {

    /**
     * 通过code获取enumClass类的枚举对象
     *
     * @param code
     * @param enumClass
     * @param <T>
     * @return
     */
    public static <T extends CodeEnum> T getByCode(Integer code, Class<T> enumClass) {
        for (T each : enumClass.getEnumConstants()) {
            if (code.equals(each.getCode())) {
                return each;
            }
        }
        return null;
    }

}
